package com.zsk.shop.controller.gop;

import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.utils.ToolUtil;
import com.zsk.shop.entity.ShopGoodsCategory;
import com.zsk.shop.model.params.ShopGoodsCategoryAddParams;
import com.zsk.shop.model.params.ShopGoodsCategoryEditParams;
import com.zsk.shop.model.results.ShopGoodsCategoryTreeResult;
import com.zsk.shop.service.ShopGoodsCategoryService;
import com.zsk.shop.service.ShopGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ljh
 * @create 2021/11/25 14:27
 */
@RestController
@Api(tags = "GOP商品分类相关")
@RequestMapping("/gop/goodsCategory")
public class GopGoodsCategoryController {
    @Resource
    private ShopGoodsCategoryService shopGoodsCategoryService;

    @Resource
    private ShopGoodsService shopGoodsService;

    @NoPermission
    @ApiOperation(value = "分类【新增】")
    @PostMapping("/addGoodsCategory.do")
    public BaseResponse addGoodsCategory(@RequestBody ShopGoodsCategoryAddParams params) {
        return shopGoodsCategoryService.addGoodsCategory(params);
    }

    @NoPermission
    @ApiOperation(value = "分类【编辑】")
    @PostMapping("/editGoodsCategory.do")
    public BaseResponse editGoodsCategory(@RequestBody ShopGoodsCategoryEditParams params) {
        if (ToolUtil.isOneEmpty(params, params.getId(), params.getCategoryName())) {
            return BaseResponse.error("必填参数缺失。");
        }
        return shopGoodsCategoryService.editGoodsCategory(params);
    }

    @NoPermission
    @ApiOperation(value = "分类【禁启用】")
    @GetMapping("/reviewGoodsCategory.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "类表中分类id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "letDisable", value = "true变成禁用状态,false变成启用状态", dataType = "Boolean", required = true)
    })
    public BaseResponse reviewGoodsCategory(Long id, Boolean letDisable) {
        return shopGoodsCategoryService.reviewGoodsCategory(id, letDisable);
    }

    @NoPermission
    @ApiOperation(value = "分类【删除】")
    @GetMapping("/deleteGoodsCategory.do")
    @ApiImplicitParam(name = "id", value = "类表中分类id", dataType = "Long", required = true)
    public BaseResponse deleteGoodsCategory(Long id) {
        return shopGoodsCategoryService.deleteGoodsCategory(id);
    }

    @NoPermission
    @ApiOperation(value = "分类【所有一二级列表】")
    @PostMapping("/goodsCategoryList.do")
    public BaseResponse<List<ShopGoodsCategoryTreeResult>> GoodsCategoryList() {
        return shopGoodsCategoryService.goodsCategoryList(true);
    }

    @NoPermission
    @ApiOperation(value = "分类【一二级联动】")
    @GetMapping("/queryGoodsCategory.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "level", value = "如 2 级分类", dataType = "Integer"),
            @ApiImplicitParam(name = "partnerCategoryNo", value = "父类的categoryNo", dataType = "String")
    })
    public BaseResponse<List<ShopGoodsCategory>> queryGoodsCategory(Integer level, String partnerCategoryNo) {
        return shopGoodsCategoryService.queryGoodsCategory(level, partnerCategoryNo, true);
    }

}
